//基础数类型

//利用forEach不可修改原数组
let newArr1 = [1, 2, 3, 4, 5, 6]
newArr1.forEach((item, index) => {
    item = item + 1
})
console.log(newArr1)  //[ 1, 2, 3, 4, 5, 6 ]


//利用forEach修改原数组
let newArr2 = [1, 2, 3, 4, 5, 6]
newArr2.forEach((item,index) => {
    return (newArr2[index] = item + 1)   //通过索引值去拿,这里的return要不要无所谓
})
console.log(newArr2)  //[ 2, 3, 4, 5, 6, 7 ]

let newArr4 = [1, 2, 3, 4, 5, 6]
let newArr5=newArr4.forEach((item, index) => {
    return (newArr4[index] = item + 1)   //通过索引值去拿,这里的return要不要无所谓
})
console.log(newArr5)  //[ 2, 3, 4, 5, 6, 7 ]
                                                                                                         

//引用类型
let newArr3 = [
    {
        name: "单色凌",
        age:31
    },
     {
        name: "徐良",
        age: 33
    },
      {
        name: "汪苏泷",
        age: 30
    }
]

newArr3.forEach((item) => {
    if (item.name == '单色凌') {
        item.age = 18
        item.name="许嵩"
    }
})
console.log(newArr3)
/*
[
  { name: '许嵩', age: 18 },
  { name: '徐良', age: 33 },
  { name: '汪苏泷', age: 30 }
]
*/